Symfony 判断用户密码

示例代码

//input user info
$username = //...
$password = //...
//获取Symfony中用户
$user = $userManager->findOneBy(array('username' => $username));
if ($container->get('security.encoder_factory')->getEncoder($user)->isPasswordValid($user->getPassword(), $password, $user->getSalt())) {
//密码正确
}

相关配置,密码加密方式

security:
encoders:
Glory\Bundle\UserBundle\Model\UserInterface: sha256